package com.ruoyi.quartz.controller;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/*
 *  @author 雨安
 *  类名： WxPayController
 *  创建时间：2025/2/18
 */
public class WxPayController {

    //apiv3 密钥
    private final static String Vx_Api_V3_Key = "ac98msLtD6fe2B620d4dM843f8N94bJH";

    //微信apiv3回调密钥
    private final static String Vx_Api_V3_Return_Key = "ac98msLtD6fe2B620d4dM843f8N94bJH";





    public static void main(String[] args) {
        try {
            // 创建请求的URL
            URL url = new URL("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Authorization", "WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\", ..."); // 这里需要替换成你的商户号和签名
            connection.setRequestProperty("Accept", "application/json");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setDoOutput(true);
            // 请求体
            String jsonInputString = "{"
                    + "\"appid\": \"wxd678efh567hg6787\","
                    + "\"mchid\": \"1230000109\","
                    + "\"description\": \"Image形象店-深圳腾大-QQ公仔\","
                    + "\"out_trade_no\": \"1217752501201407033233368018\","
                    + "\"time_expire\": \"2018-06-08T10:34:56+08:00\","
                    + "\"attach\": \"自定义数据说明\","
                    + "\"notify_url\": \"https://www.weixin.qq.com/wxpay/pay.php\","
                    + "\"goods_tag\": \"WXG\","
                    + "\"support_fapiao\": false,"
                    + "\"amount\": {"
                    + "\"total\": 100,"
                    + "\"currency\": \"CNY\""
                    + "},"
                    + "\"payer\": {"
                    + "\"openid\": \"ovqdowRIfstpQK_kYShFS2MSS9XS\""
                    + "},"
                    + "\"detail\": {"
                    + "\"cost_price\": 608800,"
                    + "\"invoice_id\": \"微信123\","
                    + "\"goods_detail\": [{"
                    + "\"merchant_goods_id\": \"1246464644\","
                    + "\"wechatpay_goods_id\": \"1001\","
                    + "\"goods_name\": \"iPhoneX 256G\","
                    + "\"quantity\": 1,"
                    + "\"unit_price\": 528800"
                    + "}]"
                    + "},"
                    + "\"scene_info\": {"
                    + "\"payer_client_ip\": \"14.23.150.211\","
                    + "\"device_id\": \"013467007045764\","
                    + "\"store_info\": {"
                    + "\"id\": \"0001\","
                    + "\"name\": \"腾讯大厦分店\","
                    + "\"area_code\": \"440305\","
                    + "\"address\": \"广东省深圳市南山区科技中一道10000号\""
                    + "}"
                    + "},"
                    + "\"settle_info\": {"
                    + "\"profit_sharing\": false"
                    + "}"
                    + "}";
            // 发送请求
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }
            // 处理响应
            int responseCode = connection.getResponseCode();
            // 这里可以根据 responseCode 进行处理
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
